<?php
include('/controller/vytvor.php');
include('/model/sutaznakategoria.php');
class sutaznakategoria extends vytvor{ 
        
        public function handle($action){
			switch ($action){
				case 'vytvor':
					return parent::handle($action);
					break;
				case 'uprav':
					if (isset($_SESSION["idupravkat"])){
						return parent::handle($action);
						break;
					} else {
						return view::load('error404', array());
						break;
					}
				case 'zrusjedukat':
					$this->zrus();
					return $this->redirect("/sutaznakategoria/vypis");
					break;
					
				case 'bezkat':
					$this->bezkat();
					return $this->redirect("/sutaz/".$_SESSION['idupravsu']."");
					break;
					
				case 'vypis':
					if (isset($_SESSION["idupravkat"])) {unset($_SESSION["idupravkat"]);}
					if (isset($_POST["pridat"])){ 
						 if ($this->nazov_check($_POST["autocomplete"])) {$this->pridaj($_POST["autocomplete"]);}
					}
					if (isset($_POST['odstran'])){
						$this->odstran($_POST['kategorie']);
						
					}
					if (isset($_SESSION["idupravsu"])){		
						$pole =$this->kategorie($_SESSION["idupravsu"]);
						return view::load('sutaznekategorie',array('kategorie'=>$pole));
					} else {
						return view::load('error404', array("todo"));
					}									
					break;
					
				case ($this->number_check2($action)):
					$_SESSION["idupravkat"]=$_GET['action'];
					return $this->redirect('/sutaznakategoria/uprav');
					break;
				default:
					return view::load('error404', array());	
			}	
		}
		
		private function zrus(){
			$mkat = New mkat();
			$mkat->zrus();
		}
		
		private function bezkat(){
			$mkat = New mkat();
			$mkat->bezkategorie();
		}
		
		private function kategorie($idkat){
			$mkat = New mkat();
			return $mkat->kategoriesutaze($idkat);
		}
		
		private  function odstran($id){
			$mkat = New mkat();
			$mkat->odstran($id);
		}    

		private function pridaj($meno){
			$mkat = New mkat();
			$mkat->pridaj($meno);
		}
}

?>